package com.wogu.strutstest.action;

import java.util.List;

import com.opensymphony.xwork2.ActionSupport;

import com.wogu.strutstest.service.AccountService;
import com.wogu.strutstest.model.Account;

public class LoginAction extends ActionSupport {
    
    private AccountService accountService;
    
    private String userName;
    
    private String password;
    
    private List<Account> accounts;
    
    private Account account;
    
    public void setAccountService(AccountService accountService) {
        this.accountService = accountService;
    }
    
    public AccountService getAccountService() {
        return accountService;
    }
    
    public void setUserName(String userName) {
        this.userName = userName;
    }
    
    public String getUserName() {
        return userName;
    }
    
    public void setPassword(String password) {
        this.password = password;
    }
    
    public String getPassword() {
        return password;
    }
    
    public void setAccounts(List<Account> accounts) {
        this.accounts = accounts;
    }
    
    public List<Account> getAccounts() {
        return accounts;
    }
    
    public void setAccount(Account account) {
        this.account = account;
    }
    
    public Account getAccount() {
        return account;
    }
    
    @Override
    public String execute() throws Exception {
        setAccount(accountService.getUserByName(userName));
        if(null == account) {
            addFieldError("userName", "user not exists");
            return INPUT;
        }
        
        setAccounts(accountService.getUsers());
        
        return SUCCESS;
    }
}